from pydantic import BaseModel
from typing import Optional
from decimal import Decimal
from datetime import datetime


class BgUserAffiliateModel(BaseModel):
    """用户推广信息模型"""
    id: Optional[int] = None
    user_id: int
    affiliate_code: str
    commission_rate: Decimal
    total_commission: Decimal
    status: int
    ali_pay_account: Optional[str] = None
    ali_pay_name: Optional[str] = None
    create_time: Optional[datetime] = None
    update_time: Optional[datetime] = None

    class Config:
        from_attributes = True


class BgUserAffiliatePageModel(BaseModel):
    """用户推广信息分页模型"""
    id: Optional[int] = None
    user_id: int
    affiliate_code: str
    commission_rate: Decimal
    total_commission: Decimal
    status: int
    ali_pay_account: Optional[str] = None
    ali_pay_name: Optional[str] = None
    create_time: Optional[datetime] = None
    update_time: Optional[datetime] = None

    class Config:
        from_attributes = True


class AffiliateStatsModel(BaseModel):
    """推广统计模型"""
    total_invitees: int = 0  # 总邀请人数
    total_orders: int = 0    # 总订单数
    total_order_amount: Decimal = Decimal('0.00')  # 总订单金额
    total_commission: Decimal = Decimal('0.00')    # 总返利金额
    pending_commission: Decimal = Decimal('0.00')  # 待结算返利
    settled_commission: Decimal = Decimal('0.00')  # 已结算返利


class InviteeInfoModel(BaseModel):
    """被邀请人信息模型"""
    user_id: int
    email: str
    register_time: datetime
    total_orders: int = 0
    total_order_amount: Decimal = Decimal('0.00')
    total_commission: Decimal = Decimal('0.00')
    last_order_time: Optional[datetime] = None
